#include "processbar.h"

#define FILESIZE 1024*1024*1024

//模拟一种场景，表示一种下载任务
void download(callback_t cb){ //参数为函数指针
  srand(time(NULL)^1023); //只是让时间变得更随机一些，先种下随机数的种子

  int total = FILESIZE;  //文件总大小
  while(total)
  {
    usleep(10000);//下载动作
    int one = rand()%(1024*1024); //单次下载量,最慢网速是0，最快网速是1兆
    total-=one;

    if(total<0) total = 0;

    int download = FILESIZE - total;//已经下载的量
    double rate = (download*1.0 / (FILESIZE)) * 100.0; //下载比例
    cb(rate);
    //printf("download: %f\n",rate);
  }
}
int main(){
  download(process_flush);
  //process();
  return 0;
}
